<!doctype html>
<html>
<head>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0">
<title>推荐商家</title>
<link href="css/style.css" rel="stylesheet" type="text/css">
<link href="css/Pager.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery-1.9.1.js"></script>
<script type="text/javascript" src="js/header&footer.js"></script>
<script type="text/javascript" src="js/jquery.pager.js"></script>
<script type="text/javascript" src="js/utils.js"></script>
<script src="js/proNav.js" type="text/javascript"></script>
</head>
<script type="text/javascript">
//全局变量
var _currentIndex = 1; //当前显示的页码
var _pageSize = 999; //每页显示的数量
var _tableId = 'funcMenuList'; //数据被添加到该 Id 指定的 Table 的 tbody 标签上
var _pagerPanel = 'pager'; //显示分页的div 的 Id
var _openId;
var _memoLength=28;	//商店简介需要剪取，设置最大的字符串长度
var _operateType = null;
/**
 * 入口
 */
$(function() {
	//获取OpenId
	_openId = getOpenId();
	loadPage(1);
});

/**
 * 跳转到详细页面
 */
function turnDetail(shopId) {
	redirectUrl('partnerDet.html?shopId=' + shopId + '&openId=' + _openId);
}

/**
 * 商店简介需要剪取，设置最大的字符串长度
 */
function cutMemo(memo){
	if(memo==null) return '';
	var len=memo.length;
	if(len>_memoLength){
		return memo.substring(0,_memoLength)+'...';
	}
	return memo;
}


/**
 * 从地址中截取 openId
 */
function getOpenId() {
	var requestUrl = window.location.href;
	return getWxParameterTs('openId', requestUrl);
}

/**
 * 将查询返回的数据显示到页面上，参数是服务器返回的查询报文，json对象
 */
function addDataToPage(message) {
	var $Table = $("#" + _tableId);
	//TODO 清除之前可能存在的 tbody 标签，这里应该有更好的办法，有时间看一下
	$("#" + _tableId + ' > tbody').remove();
	var $Tbody = $('<tbody></tbody>');
	$Table.append($Tbody);
	var row = message.result.data.length;
	for ( var i = 0; i < row; i++) {
		//获取值
		var shopId = getHeadIndexValue(i, message, 'shopId');
		var imageURL = getHeadIndexValue(i, message, 'imageURL');
		var shopName = getHeadIndexValue(i, message, 'shopName');
		var memo = getHeadIndexValue(i, message, 'memo');
		var tel = getHeadIndexValue(i, message, 'tel');
		var address = getHeadIndexValue(i, message, 'address');
		
		memo=cutMemo(memo);	//控制长度
		//创建标签
		var $Tr = $('<tr onClick="turnDetail('
				+ shopId
				+ ')"><td width="100">'
				+ '<div class="partner"><img src="'+imageURL+'" alt="'+shopName+'" /><span class="bg"></span></div></td>'
				+ '<td><strong>' + shopName + '</strong><p>' + memo
				+ '</p><p>电话：'+tel+'<p><p>地址：'+address+'<p></td></tr>');
		$Tbody.append($Tr);
	}
	//分页和其他
	//pagination(message.result.len);
	$("#sup").html('共 ' + message.result.len + ' 条');
}

/**
 * 分页，参数是 总记录数
 */
function pagination(recordCount) {
	var pageCount = Math.ceil(recordCount / _pageSize);
	$('#' + _pagerPanel).pager({
		pagenumber : _currentIndex, //当前页码,从1开始
		pagecount : pageCount, //总页码
		buttonClickCallback : function(indexClicked) {
			_currentIndex = indexClicked;
			loadPage(_currentIndex);
		}
	});
}

/**
 * 加载指定页码的数据，页码从1 开始
 */
function loadPage(pageIndex) {
	$.get('../recommendShop/find/list/' + (pageIndex - 1) + '/'
					+ _pageSize,{'operateTypeId':_operateType}, function(message) {
			if(IsEmpty(message)){
				alert('没有查询到数据！');
				return;
			}
				addDataToPage(message);
			}, 'json');
}

function chooseOperateTypeID(id){
	_operateType = id;
	loadPage(1);
	closeShopTypeChooseDiv();
}

function chooseOperatyTypeAll(){
	_operateType = null;
	loadPage(1);
	closeShopTypeChooseDiv();
}
</script>
<body>
<div class="wrapper">
  <div class='placeTit'>推荐商家<strong class='menuBtn'>筛选<img src='images/menu.png'></strong></div>
  <table width="100%" id="funcMenuList" cellspacing="1" cellpadding="0"
				border="0" class="show">
    <caption>
    推荐商家列表 <span id="sup"></span>
    </caption>
  </table>
  <div style="height: 265px; width: 100%; background: url(images/par.jpg) no-repeat center 62px #f6f6f6; text-align: center;">
    <P style="padding-top: 150px; font-family: Microsoft YaHei; color: #cdcdcd; font-size: 16px;">暂时没有商户</P>
  </div>
</div>
</div>
<div id="pager"> </div>
</body>
</html>
